package jdi;

import java.util.List;

public class CounterThread implements Runnable {

	private String name = null;

	private volatile static int index = 0;
	
	public CounterThread(String name) {
		this.name = name;
	}

	public void run() {
		try {
			
			while(true) {
				if(!this.updateIndex()) {
					break;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private boolean isValid() {
		synchronized(CounterThread.class)
		{
		return index < 10;}
	}
	
	private boolean updateIndex()
	{
		synchronized(CounterThread.class)
		{
			if(index > 100) {
				return false;
			}
			System.out.print(Thread.currentThread().getName() + " update index to: "); 
			++index;
			System.out.println(index);
			return true;
		}
	}

}
